//
//  Message1ViewController.m
//  享动
//
//  Created by 沈浩hh on 16/4/7.
//  Copyright © 2016年 HHUI. All rights reserved.
//

#import "Message1ViewController.h"

@interface Message1ViewController ()<UIWebViewDelegate>
@property (nonatomic, strong)UIWebView *webView;
@property (nonatomic, strong) UIImageView *animationImageView;

@end

@implementation Message1ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonAction:)];
    self.navigationItem.leftBarButtonItem = rightBarButton;
    
      _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT + 64 + 44)];
//    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_htmlStr]];

    NSData *html = [NSData dataWithContentsOfURL:[NSURL URLWithString:_htmlStr]];
    
    NSString *string = [[NSString alloc]initWithData:html encoding:NSUTF8StringEncoding];
    NSLog(@"%@", string);
   NSRange range1 = [string rangeOfString:@"<div class=\"read_collect\">阅读&nbsp"];
   
    NSRange rang2 = [string rangeOfString:@"var ua = navigator.userAgent"];
    NSInteger a = range1.location;
    NSInteger b = rang2.location - range1.location - 33;
    NSRange rang3 = NSMakeRange(a, b);
    NSString *stringTemp1 = @"";
    NSString *stringTemp =[string stringByReplacingCharactersInRange:rang3 withString:stringTemp1];
        stringTemp = [stringTemp stringByReplacingOccurrencesOfString:@"悦跑圈" withString:@"享动"];
   stringTemp = [NSString stringWithFormat:@"<head><style>img{width:%fpx !important;}</style></head>%@",KWIDTH - 15,stringTemp];
   [_webView loadHTMLString:stringTemp baseURL:[NSURL fileURLWithPath:[NSBundle mainBundle].bundlePath]];
    _webView.delegate = self;
    _webView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_webView];

}
#pragma mark  --- 正在加载的时候的动画 -----
- (void)addLoadingHint
{
    _animationImageView = [[UIImageView alloc]initWithFrame:CGRectMake(KWIDTH / 3, KHEIGHT / 2 - KHEIGHT / 15, KWIDTH / 3, KHEIGHT / 15 * 2)];
    NSMutableArray *imageArray = [NSMutableArray array];
    for (int i = 0; i<= 7; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"loaded_%02d.png", i]];
        [imageArray addObject:image];
    }
    _animationImageView.animationImages = imageArray;
    _animationImageView.animationDuration = 0.1 * imageArray.count;
    _animationImageView.animationRepeatCount = FLT_MAX;
    [_animationImageView startAnimating];
    [self.view addSubview:_animationImageView];
}
- (void)rightBarButtonAction:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
